// Copyright (c) Microsoft Corporation.  All rights reserved.
using System;
using System.Text;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using Microsoft.CSharp;
using System.Collections;
using System.Expressions;
using Microsoft.VisualStudio.DebuggerVisualizers;
using System.Diagnostics;
using System.Runtime.Serialization;

[assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizerPropertyGrid), typeof(ExpressionTreeVisualizerPropertyGridObjectSource), Target = typeof(Expression), Description = "Expression Tree Visualizer")]


public class ExpressionTreeVisualizerPropertyGrid : DialogDebuggerVisualizer
{
    private IDialogVisualizerService modalService;

    protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
    {

        modalService = windowService;
        if (modalService == null)
            throw new ApplicationException("This debugger does not support modal visualizers");

        ExprTreePropertyGridContainer container = (ExprTreePropertyGridContainer)objectProvider.GetObject();
        PropertyGridBrowser browser = new PropertyGridBrowser();
        browser.Add(container.tree);
        PropertyGridWindow treeForm = new PropertyGridWindow(browser, container.Expr);
        modalService.ShowDialog(treeForm);
    }

    
    protected void Show(Expression expr)
    {

        PropertyGridBrowser browser = new PropertyGridBrowser();
        browser.Add(new ExpressionTreeRootContainerNode(expr));
        PropertyGridWindow treeForm = new PropertyGridWindow(browser, expr.ToString());
        modalService.ShowDialog(treeForm);
    }
}